package com.six.backend.utils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * @author lucker
 */
public class ListUtil {
    /**
     * 去除list内的重复字符串
     * @param list
     * @return
     */
    public static List removeDuplicateWithOrder(List list)

    {
        HashSet hashSet = new HashSet();

        List newlist = new ArrayList();

        for (Iterator iterator = list.iterator(); iterator.hasNext();)

        {
            String element = (String) iterator.next();

            if (hashSet.add(element))

            {
                newlist.add(element);

            }

        }

        list.clear();

        list.addAll(newlist);

        return list;

    }

    public static List<String> removeDuplicate(List<String> list)
    {
        HashSet<String> hashSet = new HashSet<String>(list);
        list.clear();
        list.addAll(hashSet);
        return list;
    }

}
